package com.woniuxy.book.controller;

import com.woniuxy.book.util.Result;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/mq")
public class MQController {
    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/subscribe")
    public Result subscribe(String message){
        rabbitTemplate.convertAndSend("fanout","",message);
        return Result.success("success",null);
    }

    @GetMapping("/direct")
    public Result direct(Integer message){
        if (message%2==0) {
            rabbitTemplate.convertAndSend("direct","d1",message);
        }else {
            rabbitTemplate.convertAndSend("direct","d2",message);
        }
        return Result.success("success",null);
    }
}
